<?php
namespace app\index\model;

use think\Model;
use think\Db;

class DetailitemModel extends Model
{
  public function select($gid){//查询获取对应商品
    return $res = Db::table('gjc_goodsitem')->where('gid',$gid)->select();
  }
  public function goods($gid){
    return $res = Db::table('gjc_goods')->where('gid',$gid)->find();
  }
  public function num($sponsor){
    return $res = Db::table('gjc_goods')->where('g_sponsor',$sponsor)->select();
  }
  public function sponsor_user($id){
    return $res = Db::table('gjc_user')->where('uid',$id)->find();
  }
  public function order($gid,$g_item_id,$uid,$state,$order){
    $data = [
      'uid'=>$uid,
      'g_item_id'=>$g_item_id,
      'gid'=>$gid,
      'state'=>$state,
      'order_id'=>$order,
      'time'=>date('Y-m-d H:i:m',time()),
    ];
    return $res = Db::table('gjc_order')->insert($data);
  }
  public function updateOrder($order_id,$state){
    return $res = Db::table('gjc_order')->where('order_id',$order_id)->update(['state'=>$state]);
  }
  public function newMoney($uid,$newMoney){
    return $res = Db::table('gjc_user')->where('uid',$uid)->update(['money'=>$newMoney]);
  }
  public function updateGoods($gid,$money,$num){
    return $res = Db::table('gjc_goods')->where('gid',$gid)->update(['g_start_money'=>$money,'buy_num'=>$num]);
  }
  public function mainImg($gid){
    return $res = Db::table('gjc_childImg')->where('gid',$gid)->column('imgsrc');
  }
  public function goodsLikes(){
    return $res = Db::table('gjc_goods')->order('likes_num desc')->limit(3)->select();
  }
  public function jselect($gid){
    return $res = Db::table('gjc_goods')->where('gid',$gid)->value('g_name');
  }
  public function problem($gid){
    return $res = Db::table('gjc_problem')->where('gid',$gid)->select();
  }
  public function tiWen($gid,$text,$phone,$uid,$time){//修改余额
    $data = [
      'gid'=>$gid,
      'title'=>$text,
      'uid'=>$uid,
      'time'=>$time,
      'phone'=>$phone,
    ];
    return $res = Db::table('gjc_problem')->insert($data);
  }
  //删除订单
  public function deleteOrder($order_id){
    return $res = Db::table('gjc_order')->where('order_id',$order_id)->delete();
  }
  //收到商品
  public function getOrder($order_id,$state){
    return $res  = Db::table('gjc_order')->where('order_id',$order_id)->update(['state'=>$state]);
  }
}